using UnityEngine;
using UnityEngine.UI;

/****************************************************
// 功能：英雄血条显示
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2025/4/3 20:57:19
*****************************************************/

public class ItemHpHero : ItemHpSoldier
{
    public Image imgState;
    public Text textName;
    public Transform hpMarkRoot;
    public int markCount;

    public override void InitItem(MainLogicUnit unit, Transform root, int hp)
    {
        base.InitItem(unit, root, hp);
        
        SetActive(imgState, false);
        SetText(textName, unit.unitName);
        SetActive(textName);
        
        SetHpMark(hp);
    }

    public override void SetStateInfo(StateEnum state, bool show)
    {
        base.SetStateInfo(state, show);

        if (!show)
        {
            SetActive(textName);
            SetActive(imgState, false);
        }
        else
        {
            switch(state) {
                case StateEnum.Silenced:
                    SetSprite(imgState, "Images/player/silenceState");
                    break;
                case StateEnum.Knockup:
                    SetSprite(imgState, "Images/player/knockState");
                    break;
                case StateEnum.Stunned:
                    SetSprite(imgState, "Images/player/stunState");
                    break;
                //TODO
                case StateEnum.Invincible:
                case StateEnum.Restricted:
                case StateEnum.None:
                default:
                    break;
            }
            SetActive(textName, false);
            SetActive(imgState);
            imgState.SetNativeSize();
        }
    }

    /// <summary>
    /// 血量显示
    /// </summary>
    /// <param name="hp"></param>
    public void SetHpMark(int hp)
    {
        var count = hp / markCount;
        var childCount = hpMarkRoot.childCount;
        for (var i = 0; i < childCount; i++)
        {
            SetActive(hpMarkRoot.GetChild(i), i < count ? true: false);
        }
    }
}
